# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

# secfixes:
#   7.0.3-r0:
#     - CVE-2023-21808
#   7.0.5-r0:
#     - CVE-2023-28260
#   7.0.7-r0:
#     - CVE-2023-24895
#     - CVE-2023-24897
#     - CVE-2023-24936
#     - CVE-2023-29331
#     - CVE-2023-29337
#     - CVE-2023-32032
#     - CVE-2023-33126
#     - CVE-2023-33128
#     - CVE-2023-33135
#   7.0.9-r0:
#     - CVE-2023-33127
#     - CVE-2023-33170
#   7.0.10-r0:
#     - CVE-2023-38178
#     - CVE-2023-35390
#     - CVE-2023-38180
#     - CVE-2023-35391
#   7.0.11-r0:
#     - CVE-2023-36792
#     - CVE-2023-36793
#     - CVE-2023-36794
#     - CVE-2023-36796
#     - CVE-2023-36799
#   7.0.12-r0:
#     - CVE-2023-36435
#     - CVE-2023-38171
#     - CVE-2023-44487
#   7.0.13-r0:
#     - CVE-2023-36792
#     - CVE-2023-36793
#     - CVE-2023-36794
#     - CVE-2023-36796
#     - CVE-2023-36799
#     - CVE-2023-44487
#     - CVE-2023-38171
#     - CVE-2023-36435
#   7.0.14-r0:
#     - CVE-2023-36049
#     - CVE-2023-36558


pkgname=dotnet7-runtime
pkgver=7.0.14
_bldver=7.0.114-r0
pkgrel=0

# Following for dotnet build version 6.0 and up
_pkgver_macro=${pkgver%.*}
_pkgver_name=${_pkgver_macro//[.0]}
_bldver_ver=${_bldver%%-*}
pkgdesc="The .NET $_pkgver_macro Core runtime"
# x86: blocked by https://github.com/dotnet/runtime/issues/77667
# armhf: blocked by https://github.com/dotnet/runtime/issues/77663
# riscv64: port WIP https://github.com/dotnet/runtime/issues/36748
# s390x: no diskspace
arch="x86_64 armv7 aarch64"
url=https://dotnet.microsoft.com
license="MIT"
depends="
	dotnet$_pkgver_name-hostfxr
	icu-data-full
	icu-libs
	"
makedepends="dotnet$_pkgver_name-build=$_bldver"
subpackages="
	aspnetcore$_pkgver_name-runtime:aspnetcore_runtime:noarch
	aspnetcore$_pkgver_name-targeting-pack:aspnetcore_targeting_pack:noarch
	dotnet$_pkgver_name-apphost-pack:apphost_pack
	dotnet$_pkgver_name-hostfxr
	dotnet$_pkgver_name-targeting-pack:targeting_pack:noarch
	dotnet-host:host
	"
provides="dotnet$_pkgver_name=$pkgver-r$pkgrel"
options="!check" # No test suite
source="dotnet.sh.in"
builddir="$srcdir"
_libdir="/usr/lib"

case $CARCH in
	x86_64) _dotnet_arch="x64";;
	aarch64) _dotnet_arch="arm64";;
	armv7) _dotnet_arch="arm";;
	armhf) _dotnet_arch="armv6";;
	*) _dotnet_arch="$CARCH";;
esac

build() {
	sed "s|%LIBDIR%|$_libdir/dotnet|" "$srcdir"/dotnet.sh.in > "$srcdir"/dotnet.sh
}

package() {
	install -dm 755 "$pkgdir"/$_libdir/dotnet/shared

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/shared/Microsoft.NETCore.App "$pkgdir"/$_libdir/dotnet/shared/.
}

host() {
	pkgdesc="A generic driver for the .NET Core Command Line Interface"
	depends=""

	install -dm 755 \
		"$subpkgdir"/etc/profile.d \
		"$subpkgdir"/etc/dotnet \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/$_libdir/dotnet

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/dotnet "$subpkgdir"/$_libdir/dotnet/.
	ln -s $_libdir/dotnet/dotnet "$subpkgdir"/usr/bin/dotnet
	echo "$_libdir/dotnet" > "$subpkgdir"/etc/dotnet/install_location
	echo "$_libdir/dotnet" > "$subpkgdir"/etc/dotnet/install_location_$_dotnet_arch
	install -Dm 644 "$srcdir"/dotnet.sh -t "$subpkgdir"/etc/profile.d/
}

hostfxr() {
	pkgdesc="The .NET host resolver contains the logic to resolve and select the right version of the .NET SDK or runtime to use."
	depends="dotnet-host"
	provides="dotnet-hostfxr-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755	"$subpkgdir"/$_libdir/dotnet

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/host "$subpkgdir"/$_libdir/dotnet/.
}

aspnetcore_runtime() {
	pkgdesc="The ASP.NET $_pkgver_macro Core runtime"
	depends="dotnet$_pkgver_name-runtime"
	provides="aspnetcore-runtime-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/shared

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/shared/Microsoft.AspNetCore.App "$subpkgdir"/$_libdir/dotnet/shared/.
}

apphost_pack() {
	pkgdesc="The .NET $_pkgver_macro Core apphost pack"
	provides="dotnet-apphost-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.NETCore.App.Host.* "$subpkgdir"/$_libdir/dotnet/packs/.
}

targeting_pack() {
	pkgdesc="The .NET $_pkgver_macro Core targeting pack"
	provides="dotnet-targeting-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.NETCore.App.Ref "$subpkgdir"/$_libdir/dotnet/packs/.
}

aspnetcore_targeting_pack() {
	pkgdesc="The ASP.NET $_pkgver_macro Core targeting pack"
	provides="aspnetcore-targeting-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755	"$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.AspNetCore.App.Ref "$subpkgdir"/$_libdir/dotnet/packs/.
}

sha512sums="
c3f31956976b77198e72a3fef3427338b6b2961f8c121416040c1105de0ce8073e46f4c2e9ef22a001aee69cbe39621c2ddac988522693110071dfae42f2e2b7  dotnet.sh.in
"
